<?php defined('IN_IA') or exit('Access Denied');?><!DOCTYPE html>
<html lang="en">
<head>
    <?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/edithead', TEMPLATE_INCLUDEPATH)) : (include template('common/edithead', TEMPLATE_INCLUDEPATH));?>
    <!--系统 -->
    <!--这个放在最后一切平白安全-->
    <script type="text/javascript" src="./resource/js/require.js?v=20170915"></script>
    <style>
        .type1,.type2,.type3,.type4{
            display: none;
        }
    </style>
</head>
<body class="nav-md" style="min-width: 800px">
<div>
    <div class="container xc_edit_from" >
        <div class="main_container" style="overflow-x: hidden;min-height: calc(100vh - 20px);background-color: white;width: 100%;">
            <div class="col-md-12 col-xs-12">
                <div class="x_panel">
                    <?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('mymanage/webconfig/nav', TEMPLATE_INCLUDEPATH)) : (include template('mymanage/webconfig/nav', TEMPLATE_INCLUDEPATH));?>
                    <div class="x_content">
                        <br/>
                        <form class="form-horizontal" role="form" method="post" name="submit">
                            <div class="form-group">
                                <label for="name" class="col-sm-2 control-label">名称</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="name" id="name" value="<?php  echo $list['name'];?>">
                                    <input type="hidden" name="id" value="<?php  echo $list['id'];?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">打印状态</label>
                                <div class="col-sm-8">
                                    <input type="checkbox" class="js-switch" value="1" name="status"
                                           data-value="<?php  echo $list['content']['status'];?>" data-field="status">
                                </div>
                            </div>
                            <div class="form-group">
                                <label  class="col-sm-2 control-label">打印接口</label>
                                <div class="col-sm-8">
                                    <label class="radio inline">
                                        <input type="radio" class="ui-radio" name="type" id="type1" value="1" <?php  if($list['content']['type']==1) { ?>checked<?php  } ?>>易联云
                                    </label>
                                    <label class="radio inline" style="width:60px;">
                                        <input type="radio" class="ui-radio" name="type" id="type2" value="2" <?php  if($list['content']['type']==2) { ?>checked<?php  } ?>>飞鹅云
                                    </label>
                                </div>
                            </div>
                            <div class="form-group type1">
                                <label  class="col-sm-2 control-label">API 密钥</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="apikey" id="apikey" value="<?php  echo $list['content']['apikey'];?>">
                                </div>
                            </div>
                            <div class="form-group type1">
                                <label  class="col-sm-2 control-label">打印机终端号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="machine_code" id="machine_code" value="<?php  echo $list['content']['machine_code'];?>">
                                </div>
                            </div>
                            <div class="form-group type1">
                                <label  class="col-sm-2 control-label">打印机终端密钥</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="msign" id="msign" value="<?php  echo $list['content']['msign'];?>">
                                </div>
                            </div>
                            <div class="form-group type1">
                                <label  class="col-sm-2 control-label">用户id</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="partner" id="partner" value="<?php  echo $list['content']['partner'];?>">
                                </div>
                            </div>
                            <div class="form-group type2">
                                <label  class="col-sm-2 control-label">用户名</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="user" id="user" value="<?php  echo $list['content']['user'];?>">
                                </div>
                            </div>
                            <div class="form-group type2">
                                <label  class="col-sm-2 control-label">UKEY</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="ukey" id="ukey" value="<?php  echo $list['content']['ukey'];?>">
                                </div>
                            </div>
                            <div class="form-group type2">
                                <label  class="col-sm-2 control-label">打印机编号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="sn" id="sn" value="<?php  echo $list['content']['sn'];?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <input type="button" name="submit" class="btn btn-default" value="提交">
                                    <button type="button" class="btn btn-default test">测试</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php (!empty($this) && $this instanceof WeModuleSite || 1) ? (include $this->template('common/editfoot', TEMPLATE_INCLUDEPATH)) : (include template('common/editfoot', TEMPLATE_INCLUDEPATH));?>
<script>
    if($("#type1").is(":checked")){
        $(".type1").show();
    }
    if($("#type2").is(":checked")){
        $(".type2").show();
    }
    $(function(){
        $("input[name='type']").change(function(){
            if($("#type1").is(":checked")){
                $(".type1").show();
            }else{
                $(".type1").hide();
            }
            if($("#type2").is(":checked")){
                $(".type2").show();
            }else{
                $(".type2").hide();
            }
        });
        $(".test").click(function(){
            var type;
            if($("#type1").is(":checked")){
                type=1;
            }
            if($("#type2").is(":checked")){
                type=2;
            }
            if(type==1){
                var apikey=$("#apikey").val();
                var msign=$("#msign").val();
                var machine_code=$("#machine_code").val();
                var partner=$("#partner").val();
                if(apikey!="" && msign!="" && machine_code!="" && partner!=""){
                    $.ajax({
                        type:"post",
                        url:"<?php  echo url('site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'printtest','version_id'=>$_GPC['version_id']));?>",
                        data:{apikey:apikey,msign:msign,machine_code:machine_code,partner:partner,type:type},
                        dataType:'json',
                        success:function(res){
                            console.log(res);
                            swal('发送成功!', '', 'success');
                        }
                    });
                }else{
                    swal('发送失败!', '', 'error');
                }
            }else if(type==2){
                var user=$("#user").val();
                var ukey=$("#ukey").val();
                var sn=$("#sn").val();
                if(user!="" && ukey!="" && sn!=""){
                    $.ajax({
                        type:"post",
                        url:"<?php  echo url('site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'printtest','version_id'=>$_GPC['version_id']));?>",
                        data:{user:user,ukey:ukey,sn:sn,type:type},
                        dataType:'json',
                        success:function(res){
                            console.log(res);
                            swal('发送成功!', '', 'success');
                        }
                    });
                }else{
                    swal('发送失败!', '', 'error');
                }
            }
        });
        $("input[name='submit']").click(function(){
            var data=$(".form-horizontal").serialize();
            $.ajax({
                type:"post",
                url:"<?php  echo url('site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'saveprint','version_id'=>$_GPC['version_id']));?>",
                data:data,
                dataType:'json',
                success:function(res){
                    if(res.status==1){
                        swal('操作成功!', '操作成功!', 'success');
                    }else{
                        swal('操作失败!', '操作失败!', 'error');
                    }
                }
            })
        });
    })
</script>
</body>
</html>